package filter;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 * 过滤消息-tag方式实现
 */
public class FilterTagProducer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("FilterTagProducer");
        producer.setNamesrvAddr("");
        producer.start();
        String[] tags = new String[]{"TagA","TagB","TagC"};
        for (int i = 0;i<10;i++){
            Message message = new Message("Filter",tags[i%tags.length],(tags[i%tags.length]+"_FilterTagProducer").getBytes(StandardCharsets.UTF_8));
            SendResult sendResult = producer.send(message);
            System.out.println(tags[i% tags.length]+"_信息发送成功"+sendResult);

        }
        producer.shutdown();
    }
}
